package club.hicode.daydayup.parameter;

import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.util.ReflectUtil;
import feign.Param;
import org.springframework.web.bind.annotation.GetMapping;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Arrays;

/**
 * XXXX
 *
 * @author LiuChunfu
 * @date 2018/10/6
 */
public interface InterfactParamter {

    @GetMapping("/test")
    Integer show(@Param(value = "name") String name);

    static void main(String[] args) {

        //获取getMapping
        Method method = ReflectUtil.getMethod(InterfactParamter.class, "show", String.class);
        GetMapping getMapping = AnnotationUtil.getAnnotation(method, GetMapping.class);
        System.out.println(Arrays.toString(getMapping.value()));
        //获取Parameter，上文中的args
        Parameter[] parameters = method.getParameters();
        for (Parameter parameter : parameters) {
            Param param = AnnotationUtil.getAnnotation(parameter, Param.class);
            System.out.println(param.value());
        }


        //ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
        //Method show = ReflectUtil.getMethod(InterfactParamter.class, "show", String.class);
        //String[] shows = parameterNameDiscoverer.getParameterNames(show); //[name]
        //System.out.println(shows);
    }


}
